package com.huabo.contract.mysql.mapper;

import org.apache.ibatis.annotations.*;

import com.huabo.contract.mysql.entity.TblAttachmentMySql;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface TblAttachmentMySqlMapper extends tk.mybatis.mapper.common.Mapper<TblAttachmentMySql> {

	//@Insert("INSERT INTO TBL_ATTACHMENT (ATTID, ATTNAME, ATTPATH, ATTSIZE, MEMO, UPLOADTIME, UPLOADER, ISPYTHONFLAG) VALUES (ATTCHMENT_SEQUENCE.nextval, #{attname}, #{attpath}, #{attsize},  #{memo}, TO_DATE(#{uploadtime}, 'SYYYY-MM-DD HH24:MI:SS'), #{uploader},  #{ispythonflag})")
	@InsertProvider(method="add",type=TblAttachmentMySqlMapperSqlConfig.class)
	@Options(useGeneratedKeys=true, keyProperty="attid", keyColumn="ATTID")
	void add(TblAttachmentMySql att);

	@Insert("INSERT INTO TBL_ATTACHMENT (ATTNAME, ATTPATH, ATTSIZE, UPLOADER,UPLOADTIME) VALUES (#{attname}, #{attpath}, #{attsize}, #{uploader},#{uploadtime})")
	@Options(useGeneratedKeys=true, keyProperty="attid", keyColumn="ATTID")
	void insertAttachment(TblAttachmentMySql att);

	@Delete("DELETE FROM TBL_CYHW_PROJECTBUDGET_ATT WHERE ATTID = #{attid}")
	void deleteOppsiteFileRelatioin(@Param("attid") String attid) throws Exception;
	
	@Delete("DELETE FROM TBL_ATTACHMENT WHERE ATTID = #{attid}")
	void deleteFileInfoById(@Param("attid")String attid) throws Exception;
			

	@Select("SELECT * FROM TBL_ATTACHMENT WHERE ATTID = #{id}")
	TblAttachmentMySql getId(BigDecimal id);

	@Select("SELECT * FROM TBL_ATTACHMENT WHERE ATTID = #{attid}")
	@Options(useGeneratedKeys=true, keyProperty="attid", keyColumn="ATTID")
	TblAttachmentMySql findById(String attid);

	@Delete("DELETE FROM TBL_ATTACHMENT WHERE ATTID = #{attid}")
	void deleteAtt(String attid);

	@Delete("DELETE FROM TBL_CYHW_PROJECTBUDGET_ATT WHERE ATTID = #{attid}")
    void removeUnitAttByattid(Integer attid);

	@Delete("DELETE FROM TBL_ATTACHMENT where ATTID= #{attid}")
	void deleteAttachmentByattId(Integer attid);

	@Delete("DELETE FROM TBL_ATTACHMENT WHERE ATTID = #{attid}")
	void deleteAttid(BigDecimal attid);

	@Select("SELECT ATTID,ATTNAME,ATTPATH,ATTSIZE,MEMO,UPLOADTIME,UPLOADER FROM TBL_ATTACHMENT WHERE ATTID IN (SELECT ATTID FROM TBL_CYHW_UNIT_ATT WHERE contractId = #{contractId})")
    List<TblAttachmentMySql> findAttachmentListById(Integer contractId);

	@Select("SELECT ATTID,ATTNAME,ATTPATH,ATTSIZE,MEMO,UPLOADTIME,UPLOADER FROM TBL_ATTACHMENT WHERE ATTID IN (SELECT ATTID FROM TBL_CYHW_PROJECTBUDGET_ATT WHERE BUDGETID = #{budgetId})")
	List<TblAttachmentMySql> findAttachmentListByBudgetId(Integer budgetId);
}
